package printnum;

import org.apache.storm.task.OutputCollector;
import org.apache.storm.task.TopologyContext;
import org.apache.storm.topology.OutputFieldsDeclarer;
import org.apache.storm.topology.base.BaseRichBolt;
import org.apache.storm.tuple.Tuple;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

public class PrintBolt extends BaseRichBolt {
    private static final Logger logger = LoggerFactory.getLogger(PrintBolt.class);

    /**
     * Bolt组件的初始化方法
     */
    @Override
    public void prepare(Map<String, Object> map, TopologyContext topologyContext, OutputCollector outputCollector) {

    }

    /**
     * 用于接受上游发送的Tuple；如果有下游组件，可以在此方法继续发射
     */
    @Override
    public void execute(Tuple tuple) {
        Integer number = tuple.getIntegerByField("number");

        logger.info(String.valueOf(number));
    }

    @Override
    public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {

    }
}
